from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

class HomePage:
    # 页面元素元素定位: 定义为类的属性 --元组
    loc_login = (By.XPATH, '//a[text()="登录"]')

    # 操作和行为 行为为实例方法
    def wait_element_clickable(self,driver,locator):
        web_element = WebDriverWait(driver, 8, 0.5).until(EC.element_to_be_clickable(locator))
        return web_element

    def wait_element_visible(self,driver,locator):
        web_element = WebDriverWait(driver, 8, 0.5).until(EC.visibility_of_element_located(locator))
        return web_element

    def wait_element_presence(self,driver,locator):
        web_element = WebDriverWait(driver, 8, 0.5).until(EC.presence_of_element_located(locator))
        return web_element

    # 点击首页里的登录链接按钮 打开登录页面 操作-- 定义为实例方法
    def click_login_link(self,driver):
        self.wait_element_visible(driver,self.loc_login).click()